package com.mmp.main.util;

import com.mmp.common.util.Common;
import com.mmp.main.entity.HospitalDevice;

public class HtmlUtil {

	public static String[] getPPMVisitMonths(HospitalDevice hd) {
		if (hd != null) {
			String pmVisitsMonths = hd.getPmVisitsMonths();
			if (pmVisitsMonths != null)
				return Common.getConcatenatedValues(pmVisitsMonths, true);
		}
		return new String[0];
	}

	public static String getMonthesAsHtmlSelect(String name, String cssClassName) {
		String html = "<select id='" + name + "' name='" + name + "'";

		if (cssClassName != null && !cssClassName.trim().isEmpty())
			html += "class='" + cssClassName + "'";

		html += ">";
		Enums.YEAR_MONTHS[] items = Enums.YEAR_MONTHS.values();
		for (Enums.YEAR_MONTHS i : items)
			html += "<option value='" + i.getId() + "'>" + i.getText() + "</option>";
		html += "</select>";
		return html;
	}

	public static String getDevicePPMVisitMonthesAsHtmlSelect(String name, HospitalDevice device) {
		String html = "<select id='" + name + "' name='" + name + "'>";
		String[] ppmMonths = getPPMVisitMonths(device);
		if (ppmMonths != null)
			for (String m : ppmMonths)
				html += "<option value='" + m + "'>" + Enums.YEAR_MONTHS.getTextById(m) + "</option>";
		html += "</select>";
		return html;
	}

	public static String arrayFromJavaToJavaScript(String[] javaAry) {
		String jsAry = "";
		if (javaAry != null && javaAry.length > 0) {
			jsAry += "['" + javaAry[0] + "'";
			for (int i = 1; i < javaAry.length; i++)
				jsAry += ",'" + javaAry[i] + "'";
			jsAry += "]";
			return jsAry;
		}

		return "[]";
	}

	public static String arrayFromJavaToJavaScript(String concatenatedString) {
		return arrayFromJavaToJavaScript(Common.getConcatenatedValues(concatenatedString, false));
	}
}
